package com.hhkj.admin.question.common.cont;

import lombok.AllArgsConstructor;
import lombok.Getter;

import java.util.HashSet;
import java.util.Set;

/** 题目类型 single 单选题、 multiple 多选题、 judge 判断题、 case 案例题、 fillBlank 填空题、 shortAnswer 简答题 */
@Getter
@AllArgsConstructor
public enum QuestionTypeEnum {
    SINGLE("single", "单选题"),
    MULTIPLE("multiple", "多选题"),
    JUDGE("judge", "判断题"),
    FILL_BLANK("fillBlank", "填空题"),
    SHORT_ANSWER("shortAnswer", "简答题"),
    CASE("case", "案例题"),
    ;
    /** 编码 */
    private final String code;
    /** 名称 */
    private final String name;

    @Override
    public String toString() {
        return this.code;
    }

    public static Set<String> getCodeSet() {
        Set<String> codeSet = new HashSet<>();
        for (QuestionTypeEnum type : values()) {
            codeSet.add(type.code);
        }
        return codeSet;
    }

    public static String getNameByCode(String code) {
        for (QuestionTypeEnum type : values()) {
            if (type.getCode().equals(code)) {
                return type.getName();
            }
        }
        return "未知";
    }

    public static String[] arrayName() {
        QuestionTypeEnum[] types = values();
        String[] arrayName = new String[types.length];
        for (int i = 0; i < types.length; i++) {
            arrayName[i] = types[i].getName();
        }
        return arrayName;
    }
}
